package com.itheima.mySemaphore;

import java.util.concurrent.Semaphore;

public class MySemaphore implements Runnable{
    private Semaphore semaphore = new Semaphore(2);

    @Override
    public void run() {
        try {
            semaphore.acquire();
            System.out.println(Thread.currentThread().getName()+"获得了通行证开始行驶");
            Thread.sleep(2000);
            System.out.println(Thread.currentThread().getName()+"归还通行证");
            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
